//
//  LMReportController.m
//  舍品
//
//  Created by 楼 眉 on 16/4/5.
//  Copyright © 2016年 楼 眉. All rights reserved.
//

#import "LMReportController.h"
#import "LMPost.h"
#import "LMWarningLabel.h"
#import "LMReply.h"
@interface LMReportController ()

@property (weak, nonatomic) IBOutlet UITextField *tf;

@property (nonatomic,weak)  UILabel *oldLabel;
@end

@implementation LMReportController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.showsVerticalScrollIndicator = NO;
}
#pragma mark - tableView actions
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_oldLabel) {
        _oldLabel.textColor = [UIColor lightGrayColor];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *lable = cell.contentView.subviews.firstObject;
    lable.textColor = [UIColor orangeColor];
    self.oldLabel = lable;
}
- (IBAction)commitBtnClick:(id)sender
{
    if (self.post) {
        if (self.oldLabel.text.length >0 || self.tf.text.length > 0) {
            [SVProgressHUD showWithStatus:@"提交中"];
            NSString *string = [NSString stringWithFormat:@"{分类:%@};{补充:%@}",self.oldLabel.text,self.tf.text];
            self.post.reported = string;
            [self.post saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (!error) {
                    [SVProgressHUD dismiss];
                    [LMWarningLabel LM_createWarningLabelWithTitle:@"提交成功"];
                }
            }];
        }
        else
        {
            [SVProgressHUD dismiss];
            [LMWarningLabel LM_createWarningLabelWithTitle:@"请输入提交内容"];
        }

    }
    else if (self.reply)
    {
        if (self.oldLabel.text.length >0 || self.tf.text.length > 0) {
            [SVProgressHUD showWithStatus:@"提交中"];
            NSString *string = [NSString stringWithFormat:@"{分类:%@};{补充:%@}",self.oldLabel.text,self.tf.text];
            self.reply.reported = string;
            [self.reply saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (!error) {
                    [SVProgressHUD dismiss];
                    [LMWarningLabel LM_createWarningLabelWithTitle:@"提交成功"];
                }
            }];
        }
        else
        {
            [SVProgressHUD dismiss];
            [LMWarningLabel LM_createWarningLabelWithTitle:@"请输入提交内容"];
        }
    }
}
#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark - dealloc
- (void)dealloc
{
    NSLog(@"dealloc--reportVc");
}
@end
